﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Nivdal.Sponsors
{
    public partial class Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["SponsorId"].ToString() != "0")
                Response.Redirect("/Sponsors/SponsorReport.aspx");

        }

        protected void LoginButton_Click(object sender, EventArgs e)
        {
            string SponserId = "0";
            //Calls Nivdal_NewSponsorLoginProcedure SP (parameters – email and password from Email and Password text boxes). The procedure returns (SELECTS) SponsorId (decimal)
            GetNivdalData.GetNivdalData GND = new GetNivdalData.GetNivdalData();
            try
            {
                SponserId = GND.ReadNivdalIntData("@Email", "@Password", "Nivdal_NewSponsorLoginProcedure", EmailTextBox.Text.Trim(), PasswordTextBox.Text.Trim());
            }
            catch
            {
                this.ErrorLabel.Text = "Error";
            }
              //If SponsorId is 0 – login was not successful. Show "login error" message

            if (SponserId == "0" )
                this.ErrorLabel.Text = Resources.SponsorsResource.NewSponsor_loginError;
            else
            {
                Session["SponsorId"] = SponserId;
                Response.Redirect("/Sponsors/SponsorReport.aspx");

            }

        }

       
    }
}